import requests
import time
from lxml import etree

headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0",
    "content-type": "application/x-www-form-urlencoded",
}
url = "https://music.163.com/discover/playlist/"
params = {
    "order": "hot",  # 按照热度排序
    "cat": "华语",  # category 类别
    "limit": "35",
    "offset": "0",
}

response = requests.get(url, params=params, headers=headers)
# 从服务器获取的原始响应数据转换为可读的文本格式
html_str = response.content.decode()
# 把 HTML 字符串解析成树形结构，以便进行后续的处理
root = etree.HTML(html_str)
music_list = root.xpath("//div[@class='bd']/dl[@class='f-cb']/dd")
result_type_list = []
for music in music_list:
    music_type = music.xpath("./a/text()")
    result_type_list.extend(music_type)

